package net.sxnic.ugr.group.util;

import java.util.List;
import java.util.Set;

import net.sxnic.ugr.group.Group;

import org.apache.commons.lang.StringUtils;

public class GroupUtils {
	
	public static String creategroupCheckboxHtml(Set<Group> groups,
			List<Group> allgroups, String name,String clearname) {

		StringBuffer sb = new StringBuffer();

		String temp = ",";
		for (Group g : groups) {
			temp = temp + g.getGroup() + ",";
		}
 
		int i=1;
        String lstrbr="";
		 
			
		for (Group g : allgroups) {
			
			lstrbr=i%3==0?"<br>":"";
			if(!clearname.equals(g.getGroup()))
			{i++;
				if (StringUtils.contains(temp, ","+g.getGroup()+",")) {
					sb.append("<input type='checkbox' name='" + name + "' value='"
							+ g.getGroup() + "' checked='true' />&nbsp;"
							+ g.getGroup() +g.getName()+ "&nbsp;"+lstrbr);
				} else {
					sb.append("<input type='checkbox' name='" + name + "' value='"
							+ g.getGroup() + "' />&nbsp;" + g.getName()+g.getName() + "&nbsp;"+lstrbr);
				}
			}
			
		}

		return sb.toString();

	}

}
